package socket;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class Client1 {

	public static void main(String[] args) {
		try {
			System.out.println("client....");
			Socket socket = new Socket("localhost",6666);
			System.out.println("connect");
			System.out.println("connecttttt:");
			
			BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			BufferedWriter output = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

			Scanner sc = new Scanner(System.in);
			boolean should = true;
			String clientMsg;
			String serverMsg;
			while(should) {
				System.out.println("type as client:");
				clientMsg = sc.nextLine();
				System.out.println("client:"+clientMsg);
				output.write(clientMsg+"\r");
				output.flush();
				
				serverMsg = input.readLine();
				System.out.println("server:"+serverMsg);
				
				if("bye".equals(clientMsg)||"bye".equals(serverMsg)) {
					should = false;
				}
			}	
			sc.close();
			input.close();
			output.close();
			socket.close();	
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}


	}

}
